home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / nhost.arc / HOST.SLT < prev    next >
Text File  |  1989-10-08  |  21KB  |  932 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //   H O S T . S L T
  4. //
  5. //   Copyright (C) 1988 PTel and Colin Sampaleanu
  6. //
  7. //   This is a Host Mode for Telix, written as a script file.
  8. //   Ton configure Host Mode parameters such as passwords, run the 'HCONFIG'
  9. //   script. That script is run automatically if the Host Mode ocnfiguration
  10. //   file 'HOST.CNF' is missing.
  11. //
  12. //   This script will only work with Hayes compatible modems, but may be
  13. //   modified for operation with othe rmodems.
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16.  
  17. // Parameters which can be configured
  18.  
  19. str pass1[8] = "pass1",                 // The level 1 pass
  20.     pass2[8] = "pass2",                 // The level 2 (Sysop) pass
  21.     shellpass[8] = "shell",             // the pass to enter the Remote Shell
  22.     shutpass[8] = "shut",               // the pass to shut down the Host Mode
  23.     host_downloads[64],                 // where users may download from
  24.     host_uploads[64];                   // where uploaded files go
  25. int direct_connect = 0;
  26.  
  27. str current_caller[31],                 // storage of current caller's name
  28.     conn300[] = "CONNECT^M",            // modem result messages for bauds
  29.     conn1200[] = "CONNECT 1200",
  30.     conn2400[] = "CONNECT 2400",
  31.     conn9600[] = "CONNECT 9600",
  32.     conn19200[] = "CONNECT 19200";
  33. int finished_caller,                    // set to TRUE when must return to top
  34.     local_mode,                         // set to TRUE when local test mode
  35.     access_level,                       // access level of current caller
  36.     carrier_counts = 1,                 // TRUE if should watch Carrier signal
  37.     already_connected = 0,
  38.     exit_requested = 0,                 // set to TRUE if Sysop has pressed Esc
  39.     connection_lost = 0,                // set to TRUE when carrier lost
  40.     kill_user = 0;                      // set to TRUE when user must be purged
  41.  
  42. int old_scr_chk_key,                    // storage for some system variables
  43.     old_cisb_auto,                      // which we have to modify and put
  44.     old_zmod_auto,                      // back to what they were when done
  45.     old_sound;
  46. str old_down_dir[64],
  47.     old_up_dir[64];
  48.  
  49. //////////////////////////////////////////////////////////////////////////////
  50. //////////////////////////////////////////////////////////////////////////////
  51.  
  52. main()
  53.  
  54. {
  55.  int c;
  56.  
  57.  clear_scr();
  58.  
  59.  if (read_host_config_file() == -1)
  60.   {
  61.    prints("Unable to read HOST.CNF...");
  62.    prints("Running HCONFIG, the Host Mode configuration script.^M^J");
  63.    call("HCONFIG");
  64.    if (read_host_config_file() == -1)
  65.     {
  66.      prints("Still unable to read HOST.CNF. Aborting Host Mode.^M^J");
  67.      return -1;
  68.     }
  69.   }
  70.  
  71.  if (!check_directories())
  72.   {
  73.    prints("Either the upload or download directory as defined in the HOST.CNF file");
  74.    prints("doesn't exist. Either create the missing directory with the DOS 'MKDIR'");
  75.    prints("command, or run the HCONFIG script to redefine what directories to use.");
  76.    prints("Aborting Host Mode.");
  77.    return -1;
  78.   }
  79.  
  80.  old_scr_chk_key = _scr_chk_key;
  81.  _scr_chk_key = 0;
  82.  old_cisb_auto = _cisb_auto;
  83.  _cisb_auto = 0;
  84.  old_zmod_auto = _zmod_auto;
  85.  _zmod_auto = 0;
  86.  old_sound = _sound_on;
  87.  _sound_on = 0;
  88.  old_down_dir = _down_dir;
  89.  _down_dir = host_uploads;   // these are reversed because we are now the Host
  90.  old_up_dir = _up_dir;
  91.  _up_dir = host_downloads;   // these are reversed because we are now the Host
  92.  
  93.  usagelog("HOST.LOG");
  94.  
  95.  if (direct_connect)
  96.   carrier_counts = 0;
  97.  else
  98.   carrier_counts = 1;
  99.  
  100.  if (!direct_connect && carrier())
  101.   already_connected = 1;
  102.  
  103.  if (!direct_connect && !already_connected)
  104.   {
  105.    prints("Initializing modem");
  106.    cputs_tr(_auto_ans_str);
  107.   }
  108.  
  109.  while (1)
  110.   {
  111.    finished_caller = kill_user = 0;
  112.  
  113.    if (direct_connect)
  114.     carrier_counts = 0;
  115.    else
  116.     carrier_counts = 1;
  117.  
  118.    if (!direct_connect)
  119.     {
  120.      prints("^M^JHost Mode: Waiting for call...");
  121.      prints("(Press Esc to exit, or 'L' for local test mode).^M^J");
  122.  
  123.      do
  124.       {
  125.        if (carrier())
  126.         {
  127.          local_mode = 0;
  128.          break;
  129.         }
  130.  
  131.        c = inkey();
  132.        if (c)
  133.         {
  134.          if (c == 27)
  135.           {
  136.            exit_requested = 1;
  137.            break;
  138.           }
  139.          else if (c == 'l' || c == 'L')               // local teswt mode
  140.           {
  141.            prints("Local test mode entered");
  142.            local_mode = 1;
  143.            carrier_counts = 0;
  144.           }
  145.         }
  146.       }
  147.      while (toupper(c) != 'L');
  148.     }
  149.  
  150.    if (!exit_requested)
  151.     {
  152.      prints("Incoming call. Sysop: press Esc to exit, or END to terminate user.");
  153.  
  154.      do_one_caller();
  155.      if ((connection_lost || kill_user) && carrier_counts && carrier())
  156.       hangup();             // make sure nobody sneaks in
  157.     }
  158.    already_connected = 0;
  159.    if (exit_requested)
  160.     {
  161.      if (!carrier() && !direct_connect)
  162.       cputs_tr(_mdm_init_str);
  163.      _scr_chk_key = old_scr_chk_key;
  164.      _cisb_auto = old_cisb_auto;
  165.      _zmod_auto = old_zmod_auto;
  166.      _sound_on = old_sound;
  167.      _down_dir = old_down_dir;
  168.      _up_dir = old_up_dir;
  169.      prints("^M^JHost mode script finished.");
  170.      usagelog("*CLOSE*");
  171.      return 1;
  172.     }
  173.   }
  174. }
  175.  
  176. //////////////////////////////////////////////////////////////////////////////
  177.  
  178. do_one_caller()
  179.  
  180. {
  181.  str strn[80],
  182.      fname[64];
  183.  int option,
  184.      status,
  185.      c, i, i2;
  186.  
  187.  access_level = 1;
  188.  
  189.  if (already_connected)
  190.   prints("Already Connected!");
  191.  else if (carrier_counts)
  192.   {
  193.    if (!determine_baud())
  194.     ;                          // do something else here if this is a problem
  195.   }
  196.  
  197.  delay(10);
  198.  type_file("LOGO.MSG");
  199.  
  200.  flushbuf();
  201.  while (1)
  202.   {
  203.    host_send("Please enter your full name: ");
  204.    host_input_strn(current_caller, 30);
  205.    host_send("^M^J");
  206.  
  207.    if (finished_caller)
  208.     return;
  209.  
  210.    if (strlen(current_caller) >= 5)
  211.     break;
  212.   }
  213.  
  214.  access_level = ask_for_pass(3, pass1, pass2);
  215.  
  216.  if (access_level)
  217.   ustamp("Logon by ", 1, 0);
  218.  else
  219.   ustamp("Failed logon attempt by ", 1, 0);
  220.  ustamp(current_caller, 0, 1);
  221.  
  222.  if (!access_level)
  223.   {
  224.    host_send("Goodbye!^M^J");
  225.    if (carrier_counts)
  226.     {
  227.      delay(10);
  228.      hangup();
  229.     }
  230.    return;
  231.   }
  232.  
  233.  type_file("WELCOME.MSG");
  234.  
  235.  while (1)
  236.   {
  237.    if (finished_caller)
  238.     return;
  239.  
  240.    host_send("^M^JFiles  Type  Upload  Download  Shell  Chat  Goodbye ? ");
  241.    host_input_strn(strn, 1);
  242.    option = toupper(subchr(strn, 0));
  243.    host_send("^M^J");
  244.  
  245.    if (option == 'F')                 // Files directory
  246.     {
  247.      if (access_level == 2)
  248.       {
  249.        host_send("Enter 'filespec' or press Return for *.*,^M^J: ");
  250.        host_input_strn(fname, 64);
  251.        host_send("^M^J");
  252.  
  253.        if (just_filename(fname))
  254.         {
  255.          strn = host_downloads;
  256.          strcat(strn, fname);
  257.         }
  258.        else
  259.         strn = fname;
  260.       }
  261.      else
  262.       {
  263.        strn = host_downloads;
  264.        strcat(strn, "*.*");
  265.       }
  266.        
  267.      if (local_mode)
  268.       show_directory(strn, 0, carrier_counts);
  269.      else
  270.       show_directory(strn, 1, carrier_counts);
  271.      host_send("^M^J");
  272.     }
  273.    else if (option == 'T')            // Type a file
  274.     {
  275.      host_send("Type what file? ");
  276.      host_input_strn(strn, 64);
  277.      host_send("^M^J");
  278.      if (access_level != 2)             // if access 1, name and ext only
  279.       fnstrip(strn, 3, fname);
  280.      else
  281.       fname = strn;
  282.  
  283.      if (just_filename(fname))
  284.       {
  285.        strn = host_downloads;
  286.        strcat(strn, fname);
  287.        fname = strn;
  288.       }
  289.  
  290.      if (!filefind(fname, 0, strn))
  291.       {
  292.        host_send("Unable to find ");
  293.        host_send(fname);
  294.        continue;
  295.       }
  296.  
  297.      type_file(fname);
  298.     }
  299.    else if (option == 'G')            // Goodbye (Hang-up)
  300.     {
  301.      host_send("^M^JGoodbye!^M^J");
  302.      ustamp("User logged off.", 1, 1);
  303.      if (carrier_counts)
  304.       {
  305.        delay(10);
  306.        hangup();
  307.       }
  308.      return;
  309.     }
  310.    else if (option == 'C')            // Chat mode
  311.     {
  312.      prints("Sysop: Press Space to chat, any other key not to.^M^J");
  313.      c = 0;
  314.      _sound_on = 1;
  315.      for (i = 8; i && !c; --i)
  316.       {
  317.        if (carrier_counts && !carrier())
  318.         {
  319.          prints("^M^JConnection has been lost, call terminated.^M^J");
  320.          connection_lost = 1;
  321.          finished_caller = 1;
  322.          break;
  323.         }
  324.        cputc('^G');
  325.        tone(523, 20);
  326.        tone(659, 20);
  327.        tone(523, 20);
  328.        tone(659, 20);
  329.        tone(523, 20);
  330.        tone(659, 20);
  331.        for (i2 = 30; i2 && (c = inkey()) == 0; --i2)
  332.         delay(1);
  333.       }
  334.      _sound_on = 0;
  335.      if (finished_caller)
  336.       continue;
  337.      if (c != ' ' || !c)
  338.       {
  339.        host_send("Sorry, the Sysop is unavailable^M^J");
  340.        continue;
  341.       }
  342.      host_send("The sysop is here!^M^J");
  343.      chatmode(1);
  344.     }
  345.    else if (option == 'U')            // User upload
  346.     {
  347.      option = host_get_prot();
  348.      if (!option)
  349.       continue;
  350.  
  351.      status = 1;
  352.      if (option == 'T' || option == 'M' || option == 'S' ||
  353.          option == 'Y' || option == 'Z' || option == 'E')
  354.       {
  355.        send_transfer_msg();
  356.        status = receive(option, "");
  357.       }
  358.      else
  359.       {
  360.        host_send("Upload what file? ");
  361.        host_input_strn(strn, 48);
  362.        host_send("^M^J");
  363.        if (!strn)
  364.         continue;
  365.        if (access_level != 2)             // if access 1, name and ext only
  366.         fnstrip(strn, 3, fname);
  367.        else
  368.         fname = strn;
  369.  
  370.        if (just_filename(fname))
  371.         {
  372.          strn = host_uploads;
  373.          strcat(strn, fname);
  374.          fname = strn;
  375.         }
  376.  
  377.        if (filefind(fname, 23, strn))
  378.         host_send("File already exists!^M^J");
  379.        else
  380.         {
  381.          send_transfer_msg();
  382.          status = receive(option, fname);
  383.         }
  384.       }
  385.      if (status == -2)                        // Carrier lost
  386.       connection_lost = finished_caller = 1;
  387.      else if (status == -1)
  388.       host_send("^GOne or more files not received!^M^J");
  389.     }
  390.    else if (option == 'D')            // User download
  391.     {
  392.      option = host_get_prot();
  393.      if (!option)
  394.       continue;
  395.      host_send("Download what file(s)? ");
  396.      host_input_strn(strn, 48);
  397.      host_send("^M^J");
  398.      if (!strn)
  399.       continue;
  400.      if (access_level != 2)      // if not level 2, keep only name & ext
  401.       fnstrip(strn, 3, fname);
  402.      else
  403.       fname = strn;
  404.  
  405.      if (just_filename(fname))
  406.       {
  407.        strn = host_downloads;
  408.        strcat(strn, fname);
  409.        fname = strn;
  410.       }
  411.  
  412.      if (!filefind(fname, 0, strn))
  413.       {
  414.        host_send("Unable to find any matching file(s)!^M^J");
  415.        continue;
  416.       }
  417.  
  418.      status = 1;
  419.      send_transfer_msg();
  420.      status = send(option, fname);
  421.      if (status == -2)                        // Carrier lost
  422.       connection_lost = finished_caller = 1;
  423.      else if (status == -1)
  424.       host_send("^GOne or more files not received!^M^J");
  425.     }
  426.    else if (option == 'S')            // Remote shell
  427.     {
  428.      if (get_port() != 1 && get_port() != 2)
  429.       {
  430.        host_send("Remote Shell not supported on this comm port due to DOS limits!^M^J");
  431.        continue;
  432.       }
  433.  
  434.      if (ask_for_pass(3, shellpass, shellpass) != 0)
  435.       {
  436.        host_send("Type EXIT and then press Return to come back.^M^J");
  437.        if (get_baud() == 300)
  438.         delay(10);
  439.  
  440.        strn = "COM";
  441.        setchr(strn, 3, get_port() + '0'); // get right device name for redirect
  442.  
  443.        if (!local_mode)
  444.         if (redirect_dos(strn) == -1)    // redirect DOS input and output
  445.          continue;
  446.  
  447.        dos("", 0);                    // actually call the shell
  448.  
  449.        if (!local_mode)
  450.         redirect_dos("");         // very important to put things back to norm
  451.       }
  452.     }
  453.    else if (option == '^Z')            // Shut down Host Mode
  454.     {
  455.      host_send("Shut down Host mode. ");
  456.      if (!ask_for_pass(3, shutpass, shutpass))
  457.       continue;
  458.      host_send("Goodbye!^M^J");
  459.      if (carrier_counts)
  460.       hangup();
  461.      ustamp("User shut down Host Mode.", 1, 1);
  462.      finished_caller = 1;
  463.      exit_requested = 1;
  464.     }
  465.   }
  466. }
  467.  
  468. //////////////////////////////////////////////////////////////////////////////
  469.  
  470. host_get_prot()
  471.  
  472. {
  473.  str prot[1];
  474.  
  475.  host_send("^M^JModem7  SEAlink  Xmodem  1k-Xmodem  G-1k-Xmodem  Ymodem  YmodEm-g  Zmodem^M^J");
  476.  host_send("Which protocol? ");
  477.  host_input_strn(prot, 1);
  478.  host_send("^M^J");
  479.  
  480.  if (strposi("MSX1GYEZ", prot, 0) == -1)     // if illegal prot
  481.   prot = "";                                 // return 0
  482.  
  483.  return (toupper(subchr(prot, 0)));
  484.  
  485. }
  486.  
  487. //////////////////////////////////////////////////////////////////////////////
  488.  
  489. send_transfer_msg()
  490.  
  491. {
  492.  host_send("Ready to transfer file(s)... Press Ctrl-X at least twice to abort^M^J");
  493. }
  494.  
  495. //////////////////////////////////////////////////////////////////////////////
  496. // Determine the baud rate once a Carrier Detect Signal has been detected
  497. // Since no characters were read, the 'CONNECT' string should still be
  498. // in the receive buffer.
  499.  
  500. determine_baud()
  501.  
  502. {
  503.  int t3, t12, t24, t96, t192;
  504.  int tmark, stat;
  505.  int new_baud = 0;
  506.  
  507.  printsc("Determining baud... ");
  508.  
  509.  track_free(0);                // clear all existing tracks
  510.  
  511.  t3 = track(conn300, 0);       // check for connect strings
  512.  t12 = track(conn1200, 0);
  513.  t24 = track(conn2400, 0);
  514.  t96 = track(conn9600, 0);
  515.  t192 = track(conn19200, 0);
  516.  
  517.  tmark = timer_start(30);      // wait up to 3 seconds for string
  518.                              
  519.  while (!time_up(tmark))
  520.   {
  521.    if (!carrier())
  522.     {
  523.      track_free(0);            // clear all existing tracks
  524.      return 0;
  525.     }
  526.  
  527.    if (cinp_cnt())
  528.     track_addchr(cgetc());
  529.  
  530.    stat = track_hit(0);
  531.    if (stat == 0)
  532.     continue;
  533.  
  534.    if (stat == t3)
  535.     new_baud = 300;
  536.    else if (stat == t24)
  537.     new_baud = 2400;
  538.    else if (stat == t96)
  539.     new_baud = 9600;
  540.    else if (stat == t192)
  541.     new_baud = 19200;
  542.    else
  543.     new_baud = 1200;
  544.  
  545.    break;                      // have baud rate, get out
  546.   }
  547.  
  548.  if (!new_baud)                // time-up without CONNECT string
  549.   {
  550.    prints("Failed!");
  551.    track_free(0);              // clear all existing tracks
  552.    return 0;     
  553.   }
  554.  
  555.  printn(new_baud);
  556.  prints("");
  557.  set_cparams(new_baud, get_parity(), get_datab(), get_stopb());
  558.  
  559.  track_free(0);                // clear all existing tracks
  560.  return 1;                     // indicate success
  561.  
  562. }
  563.  
  564. //////////////////////////////////////////////////////////////////////////////
  565.  
  566. type_file(str fname)
  567.  
  568. {
  569.  int f;
  570.  str buf[100];
  571.  int ichar, lines_sent = 0;
  572.  
  573.  f = fopen(fname, "r");
  574.  if (!f)
  575.   return -1;
  576.  
  577.  host_send("^M^J");
  578.  
  579.  while (1)
  580.   {
  581.    if (carrier_counts)
  582.     if (!carrier())
  583.      {
  584.       connection_lost = 1;
  585.       finished_caller = 1;
  586.       fclose(f);
  587.       return 0;
  588.      }
  589.  
  590.    if (fgets(buf, 80, f) == -1)
  591.     {
  592.      fclose(f);
  593.      return 1;
  594.     }
  595.  
  596.    host_send(buf);
  597.    host_send("^M^J");
  598.    ++lines_sent;
  599.  
  600.    if (lines_sent >= 22)
  601.     {
  602.      lines_sent = 0;
  603.      host_send("[More]");
  604.      host_input();
  605.  
  606.      if (finished_caller)         // if user inactivity
  607.       {
  608.        fclose(f);
  609.        return 0;
  610.       }
  611.  
  612.      host_send("^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H");
  613.     }
  614.  
  615.    while (cinp_cnt())
  616.     {
  617.      ichar = cgetc();
  618.      if (ichar == '^C' || ichar == '^K')
  619.       {
  620.        host_send("^M^J");
  621.        fclose(f);
  622.        return 1;
  623.       }
  624.     }
  625.   }
  626. }
  627.  
  628. //////////////////////////////////////////////////////////////////////////////
  629.  
  630. host_send(str outstr)
  631.  
  632. {
  633.  
  634.  printsc(outstr);
  635.  if (!local_mode)
  636.   cputs(outstr);
  637.  
  638. }
  639.  
  640. //////////////////////////////////////////////////////////////////////////////
  641.  
  642. host_send_c(int chr)
  643.  
  644. {
  645.  
  646.  printc(chr);
  647.  if (!local_mode)
  648.   cputc(chr);
  649.  
  650. }
  651.  
  652. //////////////////////////////////////////////////////////////////////////////
  653.  
  654. host_input_strn(str buf, int maximum)
  655.  
  656. {
  657.  int i = 0, key;
  658.  
  659.  while (1)
  660.   {
  661.    key = host_input();
  662.    if (!key)                 // timeout or user disconnect
  663.     {
  664.      setchr(buf, 0, 0);      // set string to empty
  665.      return 0;               // indicate there is a problem
  666.     }
  667.  
  668.    if (key == '^M')
  669.     break;
  670.    if (key == 127 || key == 8)
  671.     {
  672.      if (i)
  673.       {
  674.        --i;
  675.        host_send_c(key);
  676.       }
  677.      continue;
  678.     }
  679.    if (i < maximum)
  680.     {
  681.      setchr(buf, i, key);
  682.      i = i + 1;
  683.     }
  684.    else
  685.     i = i + 1;
  686.   }
  687.  
  688.  if (i > maximum)
  689.   i = maximum;
  690.  
  691.  setchr(buf, i, '^0');
  692.  
  693.  if (subchr(buf, 0))
  694.   return 1;
  695.  else
  696.   return 0;
  697.  
  698. }
  699.  
  700. //////////////////////////////////////////////////////////////////////////////
  701.  
  702. host_input()
  703.  
  704. {
  705.  int c;
  706.  int t;
  707.  
  708.  t = timer_start(2400);         // 4 minutes inactivity allowed
  709.  
  710.  while (1)
  711.   {
  712.    if (time_up(t) && !direct_connect)
  713.     {
  714.      host_send("^M^J^M^JInactivity period too long. Connection terminated!^M^J");
  715.      if (carrier_counts)
  716.       hangup();
  717.      finished_caller = 1;
  718.      kill_user = 1;
  719.      return 0;
  720.     }
  721.  
  722.    if (carrier_counts)
  723.     if (!carrier())
  724.       {
  725.        prints("^M^JConnection has been lost, call terminated.^M^J");
  726.        connection_lost = 1;
  727.        finished_caller = 1;
  728.        return 0;
  729.       }
  730.  
  731.    if ((c = inkey()) != 0)
  732.     {
  733.      if (c == 27)               // ESC key, sysop wants to exit
  734.       {
  735.        finished_caller = 1;
  736.        exit_requested = 1;
  737.        return 0;
  738.       }
  739.      else if (c == 0x4f00)      // END key, temrinate user
  740.       {
  741.        prints("^M^JUser terminated!");
  742.        ustamp("User terminated!", 1, 1);
  743.        if (carrier_counts)
  744.         hangup();
  745.  
  746.        finished_caller = 1;
  747.        kill_user = 1;
  748.        return 0;
  749.       }
  750.  
  751.      else if (c <= 255)
  752.       {
  753.        if (c != 8 && c != 127)   
  754.         host_send_c(c);
  755.        return c;
  756.       }
  757.     }
  758.  
  759.    if (!local_mode)
  760.     if (cinp_cnt())
  761.      {
  762.       c = cgetc();
  763.       if (c != 8 && c != 127)
  764.        host_send_c(c);
  765.       return c;
  766.      }
  767.   }
  768. }
  769.  
  770. //////////////////////////////////////////////////////////////////////////////
  771.  
  772. ask_for_pass(int maxtries, str pass1, str pass2)
  773.  
  774. {
  775.  int i;
  776.  str strn[8];
  777.  
  778.  for (i = 0; i < maxtries; ++i)
  779.   {
  780.    if (i)
  781.     host_send("Wrong! Try again.^M^J");
  782.    host_send("Password: ");
  783.    host_input_strn(strn, 8);
  784.    host_send("^M^J");
  785.  
  786.    if (finished_caller)
  787.     return 0;
  788.  
  789.    if (!strcmpi(strn, pass1))
  790.     return 1;
  791.  
  792.    if (!strcmpi(strn, pass2))
  793.     return 2;
  794.   }
  795.  
  796.  host_send("No more chances. Access denied.^M^J");
  797.  
  798.  return 0;
  799.  
  800. }
  801.  
  802. //////////////////////////////////////////////////////////////////////////////
  803.  
  804. read_host_config_file()
  805.  
  806. {
  807.  str s[80];
  808.  int f, stat;
  809.  
  810.  s = _telix_dir;
  811.  strcat(s, "HOST.CNF");
  812.  
  813.  f = fopen(s, "r");
  814.  if (!f)
  815.   {
  816.    printsc("Can't open ");
  817.    prints(s);
  818.    return -1;
  819.   }
  820.  
  821.  stat = fgets(s, 80, f);
  822.  if (stat == -1)
  823.   goto got_error;
  824.  pass1 = s;
  825.  
  826.  stat = fgets(s, 80, f);
  827.  if (stat == -1)
  828.   goto got_error;
  829.  pass2 = s;
  830.  
  831.  stat = fgets(s, 80, f);
  832.  if (stat == -1)
  833.   goto got_error;
  834.  shellpass = s;
  835.  
  836.  stat = fgets(s, 80, f);
  837.  if (stat == -1)
  838.   goto got_error;
  839.  shutpass = s;
  840.  
  841.  stat = fgets(s, 80, f);
  842.  if (stat == -1)
  843.   goto got_error;
  844.  host_downloads = s;
  845.  
  846.  stat = fgets(s, 80, f);
  847.  if (stat == -1)
  848.   goto got_error;
  849.  host_uploads = s;
  850.  
  851.  stat = fgets(s, 80, f);
  852.  if (stat == -1)
  853.   goto got_error;
  854.  direct_connect = (toupper(subchr(s, 0)) == 'D');
  855.  
  856.  fclose(f);
  857.  return 1;
  858.  
  859. // jump here if error
  860.  
  861.  got_error:
  862.   fclose(f);
  863.   return -1;
  864.  
  865. }
  866.  
  867. //////////////////////////////////////////////////////////////////////////////
  868.  
  869. check_directories()
  870.  
  871. {
  872.  str s[80];
  873.  int i, a;
  874.  
  875.  // first remove trailing slashes
  876.  
  877.  s = host_uploads;
  878.  i = strlen(s);
  879.  if (i > 0)
  880.   if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  881.    setchr(s, i - 1, 0);
  882.  if (s && !(strlen(s) == 2 && subchr(s, 1) == ':'))
  883.   {
  884.    a = fileattr(s);
  885.    if (a == -1 || !(a & 16))
  886.     return 0;                  // not a directory or doesn't exist
  887.   }
  888.  
  889.  s = host_downloads;
  890.  i = strlen(s);
  891.  if (i > 0)
  892.   if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  893.    setchr(s, i - 1, 0);
  894.  if (s && !(strlen(s) == 2 && subchr(s, 1) == ':'))
  895.   {
  896.    a = fileattr(s);
  897.    if (a == -1 || !(a & 16))
  898.     return 0;                  // not a directory or doesn't exist
  899.   }
  900.  
  901.  return 1;
  902.  
  903. }
  904.  
  905. //////////////////////////////////////////////////////////////////////////////
  906. // returns TRUE if passed filespec is just a filename. Also handles the
  907. // forward slash as a path separator.
  908.  
  909. just_filename(str filespec)
  910.  
  911. {
  912.  int slash, space;
  913.  
  914.  if (strpos(filespec, ":", 0) != -1)
  915.   return 0;
  916.  if (strpos(filespec, "\", 0) != -1)
  917.   return 0;
  918.  if ((slash = strpos(filespec, "/")) == -1)
  919.   return 1;
  920.  
  921.  space = strpos(filespec, " ");
  922.  if (space == -1)
  923.   return 0;
  924.  if (space < slash)
  925.   return 1;
  926.  
  927.  return 0;
  928.  
  929. }
  930.  
  931. //////////////////////////////////////////////////////////////////////////////
  932.